<template>
  <div class="app-container">
    <el-form ref="form" :model="form" label-width="120px">
      <el-card class="box-card">
        <div slot="header" class="clearfix">
          <span>报单设置</span>
          <el-button style="float: right; padding: 3px 0" type="text" @click="submitForm">提交</el-button>
        </div>
        <el-form-item label="发货时间设置:">
          <el-input v-model="form.afterDay" placeholder="审核通过后(天)"></el-input>
        </el-form-item>
        <el-form-item label="允许报单日期:">
          <el-checkbox-group v-model="form.accessDay">
            <el-checkbox label="周一"></el-checkbox>
            <el-checkbox label="周二"></el-checkbox>
            <el-checkbox label="周三"></el-checkbox>
            <el-checkbox label="周四"></el-checkbox>
            <el-checkbox label="周五"></el-checkbox>
            <el-checkbox label="周六"></el-checkbox>
            <el-checkbox label="周天"></el-checkbox>
          </el-checkbox-group>
        </el-form-item>
        <el-form-item label="每日报单时间:">
          <el-time-select
            placeholder="起始时间"
            v-model="form.accessStartTime"
            :picker-options="{
              start: '00:30',
              step: '00:15',
              end: '23:30'
            }">
          </el-time-select>
          <el-time-select
            placeholder="结束时间"
            v-model="form.accessEndTime"
            :picker-options="{
              start: '00:30',
              step: '00:15',
              end: '23:30',
              minTime: form.accessStartTime
            }">
          </el-time-select>
        </el-form-item>
      </el-card>
    </el-form>
  </div>
</template>

<script>
import {pageSetting, getSetting, delSetting, addSetting, updateSetting, saveSetting} from "@/api/common/setting";
import {getToken} from '@/utils/auth'

export default {
  name: "Setting",
  data() {
    return {
      // 遮罩层
      checkList: [],
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表单参数
      form: {accessDay: []},
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询设置列表 */
    getList() {
      this.loading = true;
      pageSetting().then(response => {
        if (response.data) {
          this.form = response.data;
        } else {
          this.reset()
        }
        this.loading = false;
      });
    },
    // 表单重置
    reset() {
      this.form = {
        afterDay: null,
        accessDay: [],
        accessStartTime: null,
        accessEndTime:null
      };
      this.resetForm("form");
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          saveSetting(this.form).then(response=>{
            alert("保存成功")
            this.getList()
          })
        }
      });
    },
  }
};
</script>

